﻿Imports BusinessLogicLayer
Imports BE = BusinessEntities
Partial Class NuevoIngeniero
    Inherits System.Web.UI.Page
    Dim proy As New ProyectoBL
    Dim ing As New UsuarioBL
    Dim str_error As String
    Dim str_mensaje As String
    Public Shared str_modo As String
    Public Shared str_cliente As String

    Protected Sub btnProcesar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProcesar.Click

        Dim capanegocios As New UsuarioBL
        Dim objeto As New BE.UsuarioDTO

        Try
            'Llenamos las propiedades de la entidad ClienteBE
            objeto.Nombre = txtnombre.Text
            objeto.ApellidoUsuario = txtapellidopaterno.Text
            objeto.ApellidoUsuariomat = txtapellidomaterno.Text
            objeto.IdUsuario = txtid.Text
            objeto.PasswordUsuario = txtpass.Text
            objeto.profesiones = txtprofesion.Text
            objeto.emails = txtemail.Text

            objeto.dir = txtdireccion.Text
            objeto.CodigoArea = ddpEtapa.Text
            objeto.CodigoCargo = ddpEstado.Text

            'capanegocios.InsertarIngeniero(objeto)



            If capanegocios.InsertarIngeniero(objeto) Then

                str_mensaje = "Ingeniero registrado con éxito"
                Dim script As String = "<script language=Javascript>"
                script += "alert('" & str_mensaje & "');"
                script += "</script>"
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "script", script)

            Else

                str_mensaje = "No se registró al Ingeniero"
                Dim script As String = "<script language=Javascript>"
                script += "alert('" & str_mensaje & "');"
                script += "</script>"
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "script", script)

            End If


        Catch ex As Exception
            str_error = capanegocios.CapturaError

            Response.Redirect("Errores.aspx?id=" & str_error)
        Finally
            capanegocios = Nothing
            objeto = Nothing
        End Try

        Response.Redirect("ListadoIngeniero.aspx")

    End Sub

    Protected Sub btnProcesar_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProcesar.Load
        If Not Page.IsPostBack Then

            With ddpEtapa
                .DataSource = ing.getArea
                .DataTextField = "NOM_are"
                .DataValueField = "COD_are"
                .DataBind()
            End With

            With ddpEstado
                .DataSource = ing.getCargo
                .DataTextField = "NOM_car"
                .DataValueField = "COD_car"
                .DataBind()
            End With

        End If
    End Sub
End Class
